package com.zyj.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class NormalThreadPool {

    private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
            1,
            4,
            10,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(10),
            new ThreadPoolExecutor.AbortPolicy()
    );

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            EXECUTOR.execute(() -> {
                try {
                    TimeUnit.HOURS.sleep(1);
                } catch (InterruptedException e) {
                }
            });
            TimeUnit.MILLISECONDS.sleep(200);
            System.out.println("pool size: " + EXECUTOR.getPoolSize());
            System.out.println("queue size: " + EXECUTOR.getQueue().size());
            System.out.println("---------------");
            TimeUnit.MILLISECONDS.sleep(200);
        }
    }
}
